<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tab切换</title>
    <style>
        .tab {
            width: 100px;
            height: 50px;
            border: 2px solid black;
            display: inline-block;
        }

        .content {
            width: 300px;
            height: 300px;
            border: 2px solid black;
            /* 不显示元素 display:none 不占页面位置 visibility:hidden 会占据页面的位置*/
            /* display: none; */
            /* visibility: hidden; */
        }
        

        .tab:hover {
            background-color: bisque;
        }

        .tab:hover+.content {
            /* 显示元素 */
            display: block;
            /* visibility: visible; */
        }

        .tab:nth-of-type(1) {
            background-color: bisque;
        }

        /* t2被覆盖 找t2后面的兄弟元素t1 */
        /* has t1拥有t2直接兄弟元素*/
        /* t1拥有直接兄弟t2元素并且t2被hover的时候 */
        .t1:has(+ .t2:is(:hover)) {
            background-color: white;
        }

        .t1:has(~ .t3:is(:hover)) {
            background-color: white;
        }

        .t2:hover~.content-box .content:nth-of-type(2) {
            display: block;
        }

        .t3:hover~.content-box .content:nth-of-type(3) {
            display: block;
        }

        .tab-box {
            width: 80%;
            /* display: flex; */
        }

        .content-box {
            width: 500px;    
            position: relative;
        }

        .content {
            display: none;
            position: absolute;
            top: 0;
            background-color: antiquewhite;
        }

        .content:nth-of-type(1) {
            display: block;
        }

        .content:nth-of-type(2) {
            background-color: aquamarine;
        }

        .content:nth-of-type(3) {
            background-color: blue;
        }
    </style>
</head>

<body>
    <div class="tab-box">
        <div class="tab t1">tab1</div>
        <div class="tab t2">tab2</div>
        <div class="tab t3">tab3</div>
        <div class="content-box">
            <div class="content">内容1</div>
            <div class="content">内容2</div>
            <div class="content">内容3</div>
        </div>
    </div>
    
    <!-- hello -->
</body>

</html>